from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.


class User(AbstractUser):
    email = models.EmailField(unique=True)
    password = models.CharField(max_length=255)
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)
    files = models.ManyToManyField('File', blank=True, related_name='users', through='Access')

    def get_full_name(self):
        return f"{self.first_name} {self.last_name}"


class File(models.Model):
    file_id = models.CharField(max_length=255)
    file_name = models.CharField(max_length=255)
    file = models.FileField(upload_to='uploads/')

class Access(models.Model):
    file = models.ForeignKey(File, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True)
    isOwner = models.BooleanField(default=False)






